const path = require("path");
const fileUtils = require("../utils/file");

module.exports = async (ctx) => {
  const url = ctx.request.url;
  let filePath = url.replace("/api", "");
  
  // 修改为打包后的路径
  filePath = path.join(process.cwd(), 'data' + filePath + ".json");
  
  try {
    const res = await fileUtils.getFileJsonData(filePath);
    ctx.response.body = res;
  } catch (err) {
    console.error(err);
    ctx.response.body = {
      message: "文件资源不存在",
      status: 404,
    };
  }
};